<!DOCTYPE html>
<html>
<head>
    <title>发药--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="../Js/webUtil.js"></script>


    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "dispensing.html";
            });
        });
    </script>
</head>
<body>
<form class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病历号</td>
            <td id="ids">1101</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td id="names">黄飞鸿</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">药品名称</td>
            <td><select name="drugId" id="drugList">
            </select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">发药数量</td>
            <td><input type="text" name="number" value=""/></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button class="btn btn-primary" type="button" onclick="save()">保存</button> &nbsp;&nbsp;<button
                         class="btn btn-success" name="backid" id="backid">返回列表
                </button>
                </center>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    function save(){
        let number = $("input[name='number']").val();
        if (!number.isPositiveInteger()) {
            alert("请输入正确的数量！")
        } else {
            $.ajax({
                type: "POST",
                url: "/medicinePeople/addByList",
                data: $("form").serialize(),
                success: function (vo) {
                    if (vo.code == 200) {
                        alert(vo.obj);
                        window.location.href = "dispensing.html"
                    } else
                        alert(vo.msg);
                }
            })
        }
    }
    function loadData() {
        let url = document.location.toString();
        let data = "";
        let inputStr = "";
        for (let i = 0; i < 5; i++) {
            let patientId = url.GetValue("patientId" + i);
            if (patientId == null)
                break;
            inputStr += "<input name='ids' value='" + patientId + "' style='visibility: hidden'/>"
            data += "&ids=" + patientId
        }
        $("form").append(inputStr);
        $.ajax({
            type: "GET",
            url: "/drug/list",
            success: function (vo) {
                if (vo.code == 200) {
                    let str = "";
                    let list = vo.list;
                    for (let i = 0; i < list.length; i++) {
                        let obj = list[i];
                        str += "<option value='" + obj.id + "'>" + obj.name + "</option>";
                    }
                    $("#drugList").html(str);
                } else {
                    alert(vo.msg);
                    window.location.href = "dispensing.html";
                }
            }
        })
        $.ajax({
            type: "GET",
            data: data.substr(1),
            url: "/register",
            success: function (vo) {
                if (vo.code == 200) {
                    let list = vo.list;
                    let ids = "";
                    let names = "";
                    for (let i = 0; i < list.length; i++) {
                        let obj = list[i];
                        ids += "," + obj.id;
                        names += "," + obj.name;
                    }
                    $("#ids").html(ids.substr(1));
                    $("#names").html(names.substr(1))
                } else {
                    alert(vo.msg);
                    window.location.href = "dispensing.html";
                }
            }
        })
    }

    $(function () {
        loadData();
    })
</script>